
var events = require('events')
var eventEmitter = new events.EventEmitter();

var listener1 = function listener1() {
    console.log('listener1 proceeding!')
}

var listener2 = function listener2() {
    console.log('listener2 procedding!')
}

eventEmitter.addListener('connection', listener1)

eventEmitter.on('connection', listener2)

// listenerCount 为类方法
var count = require('events').EventEmitter.listenerCount(eventEmitter, 'connection')
console.log('connection 事件有' + count + ' 个listeners.')

eventEmitter.emit('connection')

eventEmitter.removeListener('connection', listener1)
console.log("Remove listener1")

eventEmitter.emit('connection')

count = require('events').EventEmitter.listenerCount(eventEmitter, 'connection')

console.log('connection 事件有' + count + ' 个listeners.')

console.log('END!')
